<template>
    <el-form ref="form" :model="user" :rules="rules" label-width="80px">
        <div class="text-center">
            <logo :user="user"/>
        </div>
        <el-form-item label="简称" prop="companySimpleName">
            <el-input v-model="user.companySimpleName" maxlength="11"/>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" size="mini" @click="submit">保存</el-button>
            <el-button type="danger" size="mini" @click="close">关闭</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
import { updateUserProfile } from '@/api/basic/company'
import logo from './logo'

export default {
    props: {
        user: {
            type: Object
        }
    },
    components: { logo },
    data() {
        return {
            // 表单校验
            rules: {
                companySimpleName: [
                    { required: true, message: '请输入简称', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        submit() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    updateUserProfile(this.user).then(response => {
                        this.$modal.msgSuccess('保存成功')
                    })
                }
            })
        },
        close() {
            this.$tab.closePage()
        }
    }
}
</script>
